//Add by xjk at 2013-08-13
/*
function menu_start(){
	
	var oTarget = document.getElementById("list_tab").getElementsByTagName("td");
	for(var i = 0; i<oTarget.length; i++){
	
		oTarget[i].onmouseover = function(){			
			if(this.getElementsByTagName("input")[0].value != ""){
				var oSpan = this.getElementsByTagName("span");
				for(var j=1; j<oSpan.length; j++){
					oSpan[j].style.display = "inline-block";
				}
			}		
		}
		
		oTarget[i].onmouseout = function(){
			if(this.getElementsByTagName("input")[0].value != ""){
				var oSpan = this.getElementsByTagName("span");
				for(var j=1; j<oSpan.length; j++){
					oSpan[j].style.display = "none";
				}
			}			
		}
		
		var oInput = oTarget[i].getElementsByTagName("input")[0];
		oInput.onfocus = function(){
			this.style.background = "white";
			this.style.border = "1px solid grey";
			this.style.color = "blue";
		}
		
		oInput.onblur = function(){
			this.style.background = "#ccc";
			this.style.border = "";
			this.style.color ="grey";
			
		}
		
		oInput.onchange = function(){
                                            var curVal = this.value;
                                            var targetId = this.nextSibling.nextSibling.value.split("-")[0];
                                            var data = "id="+targetId+"&name="+curVal;
                                            var targetUrl = "/Menu/edit_menu";
                                            ajax_submit(targetUrl,data);                
		}
	}	
	
	var oSpan = document.getElementsByTagName("span");
	for(var i=0; i<oSpan.length; i++){
		if(oSpan[i].getAttribute("class")=="hidden_act1" || oSpan[i].getAttribute("class")=="hidden_act2" || oSpan[i].getAttribute("class")=="hidden_act3"){
			oSpan[i].onclick = function(ev){
				if(this.getAttribute("class") == "hidden_act1"){
					del_info(ev,this);
				}else if(this.getAttribute("class") == "hidden_act3"){
					show_box(ev,this,"add");
				}else{
					show_box(ev,this,"update");	
				}
			}
		}
	}
	
	//Follow codes about ajax-submit.
	var oSub = document.getElementById("submit");
	oSub.onclick = function(ev){
                            tag = document.getElementById("m_tag").value;
                            id = document.getElementById("m_id").value;
                            appid = document.getElementById("m_appid").value;
                            name = document.getElementById("m_title").value;
                            url = document.getElementById("m_url").value;
                            type = document.getElementById("m_type").value;
                            key = document.getElementById("m_key").value;
                            sort = document.getElementById("m_sort").value;

                            if(tag == "add"){
                                var targetUrl = "/Menu/add_menu";
                                var data ="pid="+id+"&app_id="+appid+"&name="+name+"&url="+url+"&type="+type+"&key="+key+"&sort="+sort;
                            }else if(tag == "update"){ 
                                var targetUrl = "/Menu/edit_menu";
                                var data ="id="+id+"&app_id="+appid+"&name="+name+"&url="+url+"&type="+type+"&key="+key+"&sort="+sort;
                            }

                            ajax_submit(targetUrl,data);
                            
                            var oDiv = document.getElementById("hidden_box");
                            startMove(oDiv,{
                                width:0,
                                height:0,
                                top:0,
                                left:1000,
                                opacity:0
                            },20);
		}
                
                var oCancel = document.getElementById("cancel");
                oCancel.onclick = function(){
                            var oDiv = document.getElementById("hidden_box");
                            startMove(oDiv,{width:0,height:0,top:0,left:0,opacity:0},20,"","none");
                }
		
}

*/


function show_box(dataJson){
    
	var oDiv = document.getElementById("hidden_box");
	oDiv.style.display = "block";
                   
                  for(i in dataJson){
                      
                      document.getElementById("m_"+i).value =dataJson[i];
                  }
                startMove(oDiv,{width:600,height:250,top:150,left:390,opacity:100},20);	
	
}


function hidden_box(){
    var oDiv = document.getElementById("hidden_box");
    startMove(oDiv,{width:0,height:0,top:0,left:390,opacity:0},20);
    oDiv.style.display = "none";
    
}


function del_info(ev,obj){
                   if(confirm("确认删除？")){

                    var id = obj.parentNode.children[0].children[1].value.split("-")[0];
                    var data ="id="+id+"&del=1";
                    var url = "/Menu/edit_menu";
                    ajax_submit(url,data);
                   obj.parentNode.children[0].children[0].value="";                       
                   }
}


function fill_input(data,type,tag){
	var oInput = document.getElementById("hidden_box").getElementsByTagName("input");
	if(type == "add"){
            		oInput[0].value = tag;
		oInput[1].value = data[0];
		for( var i=3; i<oInput.length-2; i++){
			oInput[i].value = "";
		}	
	}else if(type == "update"){
                                    oInput[0].value = tag;
                                    oInput[1].value = data[0];
		for( var i=3; i<oInput.length-2; i++){
			oInput[i].value = data[i-2];
		}
	}
	
}


function ajax_submit(targetUrl,data){
        
        var targetObj = new Ajax(targetUrl,"GET",data);
        var objParam = targetObj.createAjax();
        targetObj.sendParam(objParam);
        targetObj.referdata(objParam);    
    
}
function getStyle(obj,attr){
	if(document.currentStyle){
		return obj.currentStyle[attr];
	}else{
		return window.getComputedStyle(obj,false)[attr];
	}

}

function startMove(obj,json,second,fn,valuex){
	clearInterval(obj.timer);
	//var stop=new Array();
	//var stopx = true;
	var stop = true;
        obj.timer=setInterval(function(){
		var k = 0;										   
		for (var attr in json){	
			if(attr=='opacity'){
			
				var iCur=parseInt(Math.floor(parseFloat(getStyle(obj,attr))*100));
				
			}else{
				var iCur=parseInt(getStyle(obj,attr));
			}
			
			var speed=(json[attr]-iCur)/10;
			speed = speed >0 ? Math.ceil(speed) : Math.floor(speed);
			if(json[attr]!=iCur){
					stop=false;
					if(attr=='opacity'){			           
						obj.style.filter='alhpa(opacity:'+(iCur+speed)+')';
						obj.style.opacity=(iCur+speed)/100;					
					}else{
						obj.style[attr]=iCur+speed+'px';
					}			
			}else{
					stop=true;
			}			
		}
		
	
		if(stop){
			clearInterval(obj.timer);
			if(fn){ 	fn();	}
                                                      if(valuex){
                                                                    obj.style.display=valuex;   
                                                        }
		}

	},second);

}

function getObjByClass(targetName,value){
	var oSpan=document.getElementsByTagName(targetName);
	var oAdd=new Array();
	var j=0;
	for(var i=0;i<oSpan.length;i++){
		if(oSpan[i].className==value){
			oAdd.push(oSpan[i]);
		}
	}
	return oAdd;
}

